package com.study.dataStructure.tree;

/**
 * @author tiny
 * @date 2021/11/11 22:23
 * @Description:
 */
public class BinaryTreeDemo {

    public static BinaryTree createTree(){
        BinaryTree tree = new BinaryTree();
        HeroNode hero1 = new HeroNode(1, "宋江");
        HeroNode hero2 = new HeroNode(2, "卢俊义");
        HeroNode hero3 = new HeroNode(3, "吴用");
        HeroNode hero4 = new HeroNode(4, "公孙胜");
        HeroNode hero5 = new HeroNode(5, "关胜");
        HeroNode hero6 = new HeroNode(6, "林冲");
        HeroNode hero7 = new HeroNode(7, "秦明");

        tree.setRoot(hero1);
        hero1.setLeft(hero2);
        hero1.setRight(hero3);
        hero2.setLeft(hero4);
        hero2.setRight(hero5);
        hero3.setLeft(hero6);
        hero3.setRight(hero7);
        /*
         *         1
         *      2     3
         *    4  5   6  7
         */
        return tree;
    }

    public static void main(String[] args) {
        BinaryTree tree = createTree();
        tree.preList(); //预计： 1 2 4 5 3 6 7
        System.out.println("========================================");
        tree.infixList(); //预计：4 2 5 1 6 3 7
        System.out.println("========================================");
        tree.postList(); // 预计： 4 5 2 6 7 3 1
        System.out.println("=============================================");
        System.out.println(tree.preSearch(5));
        System.out.println("============================================");

        tree.delNode(3);
        tree.preList();
    }

}
